package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo12 {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection();) {
            connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
            /*
            connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
            connection.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
            connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
             */
            connection.setAutoCommit(false);
            String sql ="INSERT INTO userinfo(username,password,nickname,age) VALUES(?,?,?,?)";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,"欧布奥特曼");
            preparedStatement.setString(2,"101029292");
            preparedStatement.setString(3,"欧布");
            preparedStatement.setString(4,"700");
            int number = preparedStatement.executeUpdate();
            System.out.println(number>0?"添加成功":"添加失败");
            connection.commit();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
